
<script type="text/javascript">

function setClientData(){
	idClient = document.getElementById('dossier_client_id').value;
	var xhr = getXmlHttpRequest2();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200)
			{
			var textCandidates = xhr.responseText;
			var textCandidatesData = json_parse(textCandidates);
			refreshSelect('dossier_regionClient_id', textCandidatesData['regions'], null, textCandidatesData['region']);
			refreshSelect('dossier_departementClient_id', textCandidatesData['departements'], null, textCandidatesData['departement']);
		}
	};
	xhr.open("POST","<?php print url_for('ajax/getInfosLocalisation'); ?>",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("idCli="+idClient);
}


function setLocalisationCandidates(){
	idRegion = document.getElementById('dossier_regionClient_id').value;
	var xhr = getXmlHttpRequest2();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200)
			{
			var textCandidates = xhr.responseText;
			var textCandidatesData = json_parse(textCandidates);
			refreshSelect('dossier_regionClient_id', textCandidatesData['regions'], null, textCandidatesData['region']);
			refreshSelect('dossier_departementClient_id', textCandidatesData['departements'], null, textCandidatesData['departement']);
		}
	};
	xhr.open("POST","<?php print url_for('ajax/getInfosLocalisation'); ?>",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("idReg="+idRegion);	
}
</script>
<?php if(!isset($id_dossier)) $id_dossier=$form->getObject()->id?>
<?php if(!isset($ownerClass)) $ownerClass=get_class($form->getObject())?>

<script type="text/javascript">
function showForm(className, fieldName, id){
	
	var form = document.getElementById('myForm');
	form.disabled = true;
	objElems = form.elements;
	idDiv = fieldName+'Form';
	/*		
	 *	Il faut trouver une alternative a ce inactivation. Le probleme est que s'il y avait un champ seul lecture
	 *  il devient modifiable. 		
	 */	
	/*for(i=0;i<objElems.length;i++){
	   objElems[i].disabled = true;
	}*/
	/*$('#myForm').fadeTo("fast", 0.5);*/
	getXmlHttpRequest();
	xhr.open("POST","<?php print url_for('defaultViewer/newAjax'); ?>",false);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("className="+className+"&idDiv="+idDiv+"&fieldName="+fieldName+'&id='+id);
	
	var textForm = xhr.responseText;
	document.getElementById(idDiv).innerHTML=textForm;
	document.getElementById(idDiv).style.display = "block";

	//var input = $("input:image").css({background:"yellow", border:"3px red solid"});
	//$("#myForm").submit(function () { return false; }); // so it won't submit
}

function hideForm(idDiv){
	if(document.getElementById(idDiv)){
		document.getElementById(idDiv).style.display = "none";
		document.getElementById('myForm').disabled = false;	
		document.getElementById(idDiv).innerHTML='';
		var form = document.getElementById('myForm');
		form.disabled = false;
		objElems = form.elements;
/*		
 *	Il faut trouver une alternative a ce inactivation. Le probleme est que s'il y avait un champ seul lecture
 *  il devient modifiable. 		
 */
 		/*for(i=0;i<objElems.length;i++){
		   objElems[i].disabled = false;
		}
		*/
		/*$('#myForm').fadeTo("fast", 1);*/
	}
}

function submitForm(idForm){
	var result = tmt.validator.validateForm(idForm);
	if(result){
		document.forms[idForm].submit();
	}
}

function renderList(className, fieldName,varResult)
{	
	
	getXmlHttpRequest();

	xhr.open("POST","<?php print url_for('ajax/getListeParticipantsNotifier'); ?>",false);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("ownerClass=<?php echo $ownerClass?>&ownerId=<?php echo $id_dossier;?>&fieldName="+ fieldName +"&className="+className);
	var htmlTable = xhr.responseText;
	document.getElementById('list_'+ fieldName).innerHTML = htmlTable;
		
	hideForm(fieldName+'Form');
}

function deleteItem(idDiv, className, fieldName, id)
{
	getXmlHttpRequest();
	xhr.open("POST","<?php print url_for('defaultViewer/deleteItem'); ?>",false);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("fieldName="+fieldName+'&id='+id);
	var html = xhr.responseText;
	if(html==""){
		varResult = 0;
	}else{
		varResult = 1;
	}
	renderList(className, fieldName, varResult);
	
}

</script>
